<template>
    <el-card>
        <el-row :gutter="20">
            <el-col :span="6">
                <el-input v-model="ParamsInput.cardId" placeholder="请输入会员卡号"></el-input>
            </el-col>
            <el-col :span="6">
                <el-input v-model="ParamsInput.tel" placeholder="请输入手机号"></el-input>
            </el-col>
            <el-col :span="6">
                <el-input v-model="ParamsInput.name" placeholder="请输入姓名"></el-input>
            </el-col>
            <el-col :span="6">
                <el-button type="primary" @click="loadData">查询</el-button>
                <el-button @click="resetData">重置</el-button>
            </el-col>
        </el-row>
    </el-card>
    <el-card class="mt">
        <el-table v-loading="loading" :data="dataList">
            <el-table-column type="index" label="序号" width="90"></el-table-column>
            <el-table-column prop="memberCardNumber" label="会员卡号"></el-table-column>
            <el-table-column prop="cardType" label="卡类型"></el-table-column>
            <el-table-column prop="issueDate" label="开卡日期"></el-table-column>
            <el-table-column prop="holderName" label="持有人姓名"></el-table-column>
            <el-table-column prop="holderPhone" label="持有人电话"></el-table-column>
            <el-table-column prop="cardBalance" label="卡余额"></el-table-column>
            <el-table-column label="消费记录" prop="transactionRecords">
                <template #default="scope">
                    <el-popover placement="top-start" title="消费记录" :width="200" trigger="hover"
                        content="this is content, this is content, this is content">
                        <template #reference>
                            <el-button class="m-2">消费记录</el-button>
                        </template>
                        <el-timeline style="max-width: 600px">
                            <el-timeline-item color="#0bbd87" hollow
                                v-for="(item, index) in scope.row.transactionRecords" :key="index"
                                :timestamp="item.transactionDate" placement="top">
                                <h4>{{ item.transactionAmount }}</h4>
                                <p>{{ item.transactionType }}</p>
                            </el-timeline-item>
                        </el-timeline>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="validUntil" label="有效期至"></el-table-column>
        </el-table>
        <el-pagination class="mt mb fr" v-model:current-page="pageInfo.page" v-model:page-size="pageInfo.pageSize"
            :page-sizes="[10, 20, 30, 40]" background layout="total, sizes, prev, pager, next, jumper" :total="totals"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </el-card>
</template>


<script lang="ts" setup>
import { ref } from 'vue'
import { useHttp } from '@/hook/useHttps'
interface SearchType {
    cardId: string,
    tel: string,
    name: string
}
interface DataType {
    memberCardNumber: string,
    cardType: string,
    issueDate: string,
    holderName: string,
    holderPhone: string,
    cardBalance: string
    transactionRecords: Array<{ transactionDate: string, transactionAmount: string, transactionType: string }>,
    validUntil: string

}
const ParamsInput = ref<SearchType>({
    cardId: '',
    tel: '',
    name: ''
})

const { dataList, totals, loading, pageInfo, loadData, handleSizeChange, handleCurrentChange, resetPagination } = useHttp<DataType>('/member', ParamsInput)
const resetData = () => {
    ParamsInput.value = {
        cardId: '',
        tel: '',
        name: ''
    }
    resetPagination()
}
</script>